/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts;

import entity.Vacancy;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.VacancyModel;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author SonLT
 */
public class VacancyUpdateAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        VacancyInsertForm vif = (VacancyInsertForm) form;

        Vacancy v = new Vacancy();
        v.setVacancyID(vif.getTxtvacancyID());
        v.setDepartmentID(vif.getCbxDepartment());
        v.setVacancyTitle(vif.getTxtvacancyTitle());
        v.setNumOfJob(Integer.parseInt(vif.getTxtNumOfJob()));
        v.setSalary(vif.getTxtSalary());
        v.setExperience(vif.getTxtExperience());
        v.setStartDate(vif.getTxtStartdate());
        v.setCloseDate(vif.getTxtClosedate());
        v.setStatus(vif.getTxtStatus());
        v.setPlace(vif.getTxtPlace());

        VacancyModel vm = new VacancyModel();
        if (vm.updateVacancy(v)) {
            return mapping.findForward("success");
        }

        return mapping.findForward("fail");
    }
}
